﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Students.Bases;

namespace Students
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                loginAlert.Visible = false;
        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            string userName = tbUsername.Text;
            string passWord = tbPassword.Text;
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
            {
                AlertError("Please input require fields");
                return;
            }
            BLStudents std = new BLStudents();

            var userLogin = std.GetUser(userName.Trim(),passWord);

            if (userLogin != null)
            {
                Session["OAuth"] = userLogin;
                Response.Redirect(ResolveUrl("~/Courses.aspx"));
            }
            else
            {
                AlertError("Login infomation incorrect");
                return;
            }
        }

        protected void AlertError(string msg)
        {
            loginAlert.Attributes["class"] = "alert alert-danger";
            loginAlert.InnerHtml = msg;
            loginAlert.Visible = true;
        }
    }
}